package com.levi.filter;

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.core.Ordered;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 1.自定义网关过滤器   针对某一个路由生效
 * 2.通过configuration  配置到web容器中
 */
public class CustomGatewayFilter implements GatewayFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        //TODO 这里面写业务逻辑
        System.out.println("自定义网关过滤器被执行");
        return chain.filter(exchange);   //继续往下执行
    }

    /**
     * 如果有多个过滤器  ，此方法返回的数值越小，执行优先级越高
     * @return
     */
    @Override
    public int getOrder() {
        return 0;
    }
}
